package leetcode;

/*
输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
示例 1：
输入：head = [1,3,2]
输出：[2,3,1]
限制：
0 <= 链表长度 <= 10000
*/

import java.util.Stack;
import java.util.Vector;

public class Offer_006 {
    public static void main(String[] args) {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(3);
        ListNode node3 = new ListNode(2);
        node1.next = node2;
        node2.next = node3;
        System.out.println(new Solution().reversePrint(node1));
    }
    static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
        }
    }
    static class Solution {
        Stack<Integer> stack = new Stack<Integer>();
        public int[] reversePrint(ListNode head) {
            while (null != head){
                stack.add(head.val);
                head = head.next;
            }
            int[] ret = new int[stack.size()];
            int i = 0;
            while (!stack.isEmpty()){
                ret[i++] = stack.pop();
            }
            return ret;
        }
    }
}

